package com.cpecc.dao.system;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import com.cpecc.model.system.Role;

@Repository
public class RoleDao {

	@Resource
	private SessionFactory sessionFactory;
	
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	
	@SuppressWarnings("unchecked")
	public List<Role> getDepRoleList(){
		String hql="from Role t where t.roleLX=2";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		return query.list();
	}
	
	@SuppressWarnings("unchecked")
	public List<Role> getUserRoleList(){
		String hql="from Role t where t.roleLX=1";
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		return query.list();
	}
	
	public Role get(String id){
		return (Role)sessionFactory.getCurrentSession().get(Role.class, id);
	}
	
	public Role getRole(String id){
		Session session=sessionFactory.openSession();
		Role role=(Role) session.get(Role.class, id);
		session.close();
		return role;
	}	
}
